package yangwenzhe;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class DoubleColorball {
    public static void main(String[] args) {
        // 生成随机的红球号码（可重复）
        Random random = new Random();
        List<Integer> winningRedBalls = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            winningRedBalls.add(random.nextInt(33) + 1);
        }

        // 生成随机的蓝球号码
        int winningBlueBall = random.nextInt(16) + 1;

        // 获取用户输入的红球号码（可重复）
        Scanner scanner = new Scanner(System.in);
        List<Integer> userRedBalls = new ArrayList<>();
        for (int i = 1; i <= 6; i++) {
            boolean validInput = false;
            while (!validInput) {
                System.out.println("请输入第 " + i + " 个红球号码（1 - 33）：");
                int num = scanner.nextInt();
                if (num < 1 || num > 33) {
                    System.out.println("号码超出范围，请重新输入：");
                } else {
                    userRedBalls.add(num);
                    validInput = true;
                }
            }
        }

        // 获取用户输入的蓝球号码
        System.out.println("请输入蓝球号码（1 - 16）：");
        int userBlueBall;
        do {
            userBlueBall = scanner.nextInt();
            if (userBlueBall < 1 || userBlueBall > 16) {
                System.out.println("号码超出范围，请重新输入：");
            }
        } while (userBlueBall < 1 || userBlueBall > 16);

        // 计算命中的红球数量
        int hitRedBalls = 0;
        for (int ball : userRedBalls) {
            if (winningRedBalls.contains(ball)) {
                hitRedBalls++;
            }
        }

        // 确定中奖级别
        String prizeLevel;
        if (hitRedBalls == 6 && userBlueBall == winningBlueBall) {
            prizeLevel = "一等奖";
        } else if (hitRedBalls == 6) {
            prizeLevel = "二等奖";
        } else if (hitRedBalls == 5 && userBlueBall == winningBlueBall) {
            prizeLevel = "三等奖";
        } else if (hitRedBalls == 5 || (hitRedBalls == 4 && userBlueBall == winningBlueBall)) {
            prizeLevel = "四等奖";
        } else if (hitRedBalls == 4 || (hitRedBalls == 3 && userBlueBall == winningBlueBall)) {
            prizeLevel = "五等奖";
        } else if ((hitRedBalls == 2 && userBlueBall == winningBlueBall) ||
                (hitRedBalls == 1 && userBlueBall == winningBlueBall) ||
                (hitRedBalls == 0 && userBlueBall == winningBlueBall)) {
            prizeLevel = "六等奖";
        } else {
            prizeLevel = "未中奖";
        }

        // 输出结果
        System.out.println("中奖红球号码：" + winningRedBalls);
        System.out.println("中奖蓝球号码：" + winningBlueBall);
        System.out.println("您输入的红球号码：" + userRedBalls);
        System.out.println("您输入的蓝球号码：" + userBlueBall);
        System.out.println("您命中了 " + hitRedBalls + " 个红球和 " + (userBlueBall == winningBlueBall? "1" : "0") + " 个蓝球。");
        System.out.println("您的中奖级别是：" + prizeLevel);

        scanner.close();
    }
}